<?php
class Model_UserManager
{
	public function checkLogin($username,$password){
		$objDB = DbManager::getConnection();
		if($username == null || $password == null){
			return false;
		}
		$password = hash('md5', $password);
		$strSql = "SELECT user_id ";
		$strSql.= " FROM mt_user ";
		$strSql.= " Where user_name = :username AND password = :password ";
		$bind = array();
		$bind['username'] = $username;
		$bind['password'] = $password;
		try{
			$statement = $objDB->query($strSql,$bind);
			$list = $statement->fetchAll();
			if(count($list) == 1){
				return $list[0]['user_id'];
			}else{
				return null;
			}
		}catch (Exception $e){
			die("Model_UserManager.checkLogin errors:".$e->getMessage());
		}
		return null;
	}
	
	public function getUserDetail($user_id){
		$objDB = DbManager::getConnection();
		if($user_id == null){
			return false;
		}
		$strSql = "SELECT * ";
		$strSql.= " FROM mt_user ";
		$strSql.= " Where user_id = :user_id ";
		$bind = array();
		$bind['user_id'] = $user_id;
		try{
			$statement = $objDB->query($strSql,$bind);
			$list = $statement->fetchAll();
			if(count($list) == 1){
				return $list[0];
			}else{
				return null;
			}
			
		}catch (Exception $e){
			die("Model_UserManager.getUserDetail errors: ".$e->getMessage());
		}
		return null;
	}
	
}